package practica1;

public abstract class FuncionMultiVar extends Funcion {
	
	protected int n;
	
	abstract public double calcAptitud(double[] f);
	
	public FuncionMultiVar(double xMin, double xMax, double precision, int n){
		super(xMin,xMax,precision);
		this.n = n;
		longCromo = ((int)(Math.ceil((Math.log(1+((xMax-xMin)/precision)))/Math.log(2))))*n;
	}	
	
	public int getN(){
		return n;
	}
	
	public int getLongGen(){
		return longCromo/n;
	}

	public double[] calcFenotipo(boolean[] genes) {
		double[] f = new double[n];
		boolean[] g = new boolean[getLongGen()];
		int k = 0;
		for (int i=0; i<n; i++) {
			for (int j=0; j<getLongGen(); j++) {
				g[j] = genes[k];
				k++;
			}
			f[i] = calcFenotipo(g,xMin,xMax,g.length);
		}
		return f;
	}
	
}
